﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;

namespace WebApplication1.Controllers
{
    public class UpfileController : Controller
    {
        // GET: Upfile
        public ActionResult Upfile()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Upfile(HttpPostedFileBase file)
        {
            if (file != null)
            {
                var ran = new Random();
                var fileName = DateTime.Now.ToString("yyyyMMddHHmmss")+ran.Next(100,999)+Path.GetExtension(file.FileName);
                file.SaveAs(Server.MapPath("~/Uploads/" + fileName));
                ViewBag.text = "上传成功";
            }
            else
            {
                ViewBag.text = "未选择文件";
            }
            return View();
        }
    }
}